package cn.edu.nju.software.cdiy.action.user.login;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.edu.nju.software.cdiy.bean.Scomment;
import cn.edu.nju.software.cdiy.bean.User;
import cn.edu.nju.software.cdiy.service.impl.ScommentServiceImpl;
import cn.edu.nju.software.cdiy.util.BusinessConstant;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class AddScommentAction extends ActionSupport implements SessionAware {

	private Map<String, Object> session;
	private ScommentServiceImpl scommentService;
	private Scomment comment;

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;;
	}

	public void setScommentService(ScommentServiceImpl scommentService) {
		this.scommentService = scommentService;
	}

	public Scomment getComment() {
		return comment;
	}

	public void setComment(Scomment comment) {
		this.comment = comment;
	}
	
	@Override
	public String execute() throws Exception {
		User user = (User) session.get(BusinessConstant.S_USER);
		if (user == null) {
			return LOGIN;
		} else {
			Long userId = user.getId();
			String userName = user.getName();
			comment.setUserid(userId);
			comment.setUsername(userName);
			comment = scommentService.saveScomment(comment);

		}
		return SUCCESS;
	}

}
